using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using SMS.ProcessUtils;
using SMS.SmManager;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MOReceiver : System.Web.Services.WebService
{
    public AuthHeader Authentication;

    public MOReceiver()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    public class AuthHeader : SoapHeader
    {
        public string Username;
        public string Password;
    }

    [SoapHeader("Authentication")]
    [WebMethod]
    public int receiverMO(string User_ID, string Service_ID, string Command_Code, string Message, string Request_ID)
    {
        if (Authenticated())
        {
            int requestId = 0;
            try
            {
                requestId = int.Parse(Request_ID);
            }
            catch { return 5; }

            if (User_ID.Substring(0, 2) != "84")
                return 1;

            if (Message.Trim().Length > 160)
                return 4;

            if (Command_Code.Trim().Substring(0, 3).ToLower() != "dam")
                return 2;

            bool bln = false;
            //bln = MessageInManager.Insert(requestId, User_ID, Service_ID, Command_Code, Message, DateTime.Now, 0);

            if (bln == true) return 0;
            else 
                return -1;
        }
        else
            return 99;
    }

    private bool Authenticated()
    {
        if (Authentication.Username == "bluesea" && Authentication.Password == "connected") return true;
        else
            return false;
    }
}
